#pragma once

#include "Element.h"

#include "Comment.h"

namespace uml {

Element::Element(const QString& umlType)
    : BaseElement(umlType) {}

void Element::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    BaseElement::fromJson(json, errorList);
    JsonSerializable::fromJsonArray(ownedComments_, "ownedComments", json, errorList);
    JsonSerializable::fromJsonArray(ownedElements_, "ownedElements", json, errorList);
    
}

void Element::toJson(QJsonObject& json) {
    BaseElement::toJson(json);
    JsonSerializable::toJsonArray(ownedComments_, "ownedComments", json);
    JsonSerializable::toJsonArray(ownedElements_, "ownedElements", json);
    
}

/// <summary>
/// allOwnedElements
    /// The query allOwnedElements() gives all of the direct and indirect ownedElements
    /// of an Element.
/// </summary>
    /// <code>
    /// result = (ownedElement->union(ownedElement->collect(e | e.allOwnedElements()))->asSet())
    /// </code>
shared_ptr<vector<Element>> Element::allOwnedElements() const
{
    return nullptr;
}

/// <summary>
/// mustBeOwned
    /// The query mustBeOwned() indicates whether Elements of this type must have an
    /// owner. Subclasses of Element that do not require an owner must override this
    /// operation.
/// </summary>
    /// <code>
    /// result = (true)
    /// </code>
bool Element::mustBeOwned() const
{
    return false;
}

/// <summary>
/// ownedComments getter
/// The Comments owned by this Element.
/// </summary>
vector<shared_ptr<Comment>>& Element::ownedComments() {
    return ownedComments_;
}

/// <summary>
/// ownedElements getter
/// The Elements owned by this Element.
/// </summary>
vector<shared_ptr<Element>>& Element::ownedElements() {
    return ownedElements_;
}

/// <summary>
/// owner getter
/// The Element that owns this Element.
/// </summary>
shared_ptr<Element> Element::owner() const {
    return owner_;
}

/// <summary>
/// owner setter
/// The Element that owns this Element.
/// </summary>
void Element::setOwner(shared_ptr<Element> value) {
    owner_ = value;
}

} // namespace uml
